﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml;

namespace SemestralniPraceY35VAN
{
    class Stats
    {
        /// <summary>
        /// Properties of the stats.
        /// </summary>
        private Hashtable properties;

        /// <summary>
        /// 
        /// </summary>
        public int Checkins { get { if (properties.ContainsKey("checkins")) return int.Parse((string)properties["checkins"]); else return -1; } }

        /// <summary>
        /// 
        /// </summary>
        public int HereNow { get { if (properties.ContainsKey("herenow")) return int.Parse((string)properties["herenow"]); else return -1; } }

        /// <summary>
        /// 
        /// </summary>
        public BeenHere BeenHere { get { if (properties.ContainsKey("beenhere")) return (BeenHere)properties["beenhere"]; else return null; } }

        /// <summary>
        /// 
        /// </summary>
        public Mayor Mayor { get { if (properties.ContainsKey("mayor")) return (Mayor)properties["mayor"]; else return null; } }

        /// <summary>
        /// Constructs an object representing stats.
        /// </summary>
        /// <param name="special">XML node with information about the stats</param>
        public Stats(XmlNode stats)
        {
            properties = new Hashtable();

            if (stats.Name == "stats")
            {
                for (int i = 0; i < stats.ChildNodes.Count; i++)
                {
                    switch (stats.ChildNodes[i].Name)
                    {
                        case "beenhere":
                            properties.Add(stats.ChildNodes[i].Name, new BeenHere(stats.ChildNodes[i]));
                            break;
                        case "mayor":
                            properties.Add(stats.ChildNodes[i].Name, new Mayor(stats.ChildNodes[i]));
                            break;
                        default:
                            properties.Add(stats.ChildNodes[i].Name, stats.ChildNodes[i].InnerText);
                            break;
                    }
                }
            }
            else
            {
                throw new IOException("Not Stats!");
            }
        }
    }
}
